package com.strato.batch.base.v1_0_0.demo;

import java.util.ArrayList;
import java.util.List;

import com.strato.batch.base.v1_0_0.api.JobConsumerFactory;
import com.strato.batch.base.v1_0_0.api.JobProducer;
import com.strato.batch.base.v1_0_0.batch.BatchExecutor;
import com.strato.batch.base.v1_0_0.batch.BatchJobExecutionConfig;
import com.strato.batch.base.v1_0_0.common.ListJobProducer;

public class Main {

	public static void main(String[] args) {
		t1();
		t2();
	}
	
	public static void t1(){
		BatchJobExecutionConfig<Number> config=new BatchJobExecutionConfig<Number>();
		JobConsumerFactory<Number> jobConsumerFactory=new NumberJobConsumerFactory();
		config.setJobConsumerFactory(jobConsumerFactory);
		BatchExecutor<Number> executor=new BatchExecutor<Number>("n");
		List<Number> list=new ArrayList<Number>();
		for(int i=0;i<100;i++){
			list.add(i);
		}
		JobProducer<Number> producer=new ListJobProducer<Number>(list);
		long start=System.currentTimeMillis();
		executor.execute(producer, config);
		long end=System.currentTimeMillis();
		System.out.println("T1:"+(end-start)/1000.0+"s");
	}
	
	public static void t2(){
		long start=System.currentTimeMillis();
		for(int i=0;i<100;i++){
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		long end=System.currentTimeMillis();
		System.out.println("T2:"+(end-start)/1000.0+"s");
	}

}
